# from plugin import MSsqlClient
from config import Config
from datetime import datetime
import time


class person:
    __kind = "kind"

    def __init__(self, name, age, job, id=None):
        self.name = name
        self.age = age
        self.job = job
        self.id1 = id or 0


# client = MSsqlClient(**Config.module_config.huada.record_link)


def executemany(num):
    print("executemany start:", datetime.now())
    plist = []
    for i in range(num):
        p = person('executemany' + str(i), i, 'executemany' + str(i))
        p.a = 'a'
        p.b = 'b'
        p.c = 'c'
        p.d = 'd'
        p.e = 'e'
        p.f = 'f'
        p.g = 'g'
        p.h = 'h'
        plist.append(p)
    client.insert_objects(plist, tablename='person2')
    print("executemany end:", datetime.now())


def execute(num):
    print("execute start:", datetime.now())
    plist = []
    for i in range(num):
        p = person('execute' + str(i), i, 'execute' + str(i))
        plist.append(p)
    client.insert_objects(plist, create_table=True, create_time=True, increment_id=True)
    print("execute end:", datetime.now())


def executeevery(num):
    time1 = time.time()
    print("executeevery start:", time1)
    timedif = 0  # 计算时间差
    for i in range(num):
        p = person('executeevery' + str(i), i, 'executeevery' + str(i))
        p.a = 'a'
        p.b = 'b'
        p.c = 'c'
        p.d = 'd'
        p.e = 'e'
        p.f = 'f'
        p.g = 'g'
        p.h = 'h'
        client.execute("insert into person2 (name, age, job,a,b,c,d,e,f,g,h) values(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       tuple(p.__dict__.values()))
        timedif += time.time() - time1

    print("executeevery time:", timedif)
    time2 = time.time()
    print("executeevery end:", time2)
    print("executeevery time:", time2 - time1)


def insertmany(num):
    time1 = time.time()
    print("insertmany start:", time1)
    plist = []
    for i in range(num):
        p = person('insertmany' + str(i), i, 'insertmany' + str(i))
        p.a = 'a'
        p.b = 'b'
        p.c = 'c'
        p.d = 'd'
        p.e = 'e'
        p.f = 'f'
        p.g = 'g'
        p.h = 'h'
        plist.append(p)
    # client.create_table('person2', tuple(plist[0].__dict__.keys()))
    client.insertmany(
        'insert into person2 (name, age, job,a,b,c,d,e,f,g,h) values(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',
        # client.insertmany('insert into person1 (name, age, job) values(?,?,?)',
        [tuple(data.__dict__.values()) for data in plist],
        each=100)
    time2 = time.time()
    print("insertmany end:", time2)

    # 计算时间差
    print("insertmany time:", time2 - time1)


def hide_test():
    p = person('hide_test', 1, 'hide_test')
    print(p.__dict__)


class extend_person(person):
    dd = "dd"

    def __init__(self, name, age, job):
        super().__init__(name, age, job)


def extend_test():
    p = extend_person('extend_test', 1, 'extend_test')
    print(p.__dict__)
    # print(p.__kind)
    # print(extend_person.__kind)
    print(extend_person.dd)


def copy_test():
    a = {'a': ['a1', 'a2'], 'b': ['b1', 'b2']}
    b = a.copy()
    b['a'].append('a3')
    print(a)
    print(b)


def copy_test1():
    from copy import deepcopy
    plist = []
    for i in range(3):
        p1 = person('copy_test1', i, 'copy_test1')
        plist.append(p1)
    plist1 = plist.copy()
    plist.append(person('copy_test1', 3, 'copy_test1'))
    for p in plist1:
        print(p.__dict__)
    print('-----------------')
    for p in plist:
        print(p.__dict__)

    print('-----------------')
    plist = list(set(plist).difference(set(plist1)))
    for p in plist:
        del p.id
        print(p.__dict__)


def dict_copy_test():
    dic = {'a': ['a1', 'a2'], 'b': ['b1', 'b2']}
    dic1 = {}
    for k, v in dic.items():
        dic1[k] = v.copy()
    dic['a'].append('test111')
    for k, v in dic.items():
        print(k, v)

    print('-----------')
    for k, v in dic1.items():
        print(k, v)
        dic[k] = list(set(dic[k]).difference(set(v)))
    print('---------------')

    for k, v in dic.items():
        print(k, v)


def test_dic_key():
    dic = {1: 'a', 2: 'b'}
    for k, v in dic.items():
        print(k, v)


def do_init():
    from base import MY_STORED_CACHE, _record_my_stored_cache
    MY_STORED_CACHE.clear()
    _record_my_stored_cache()
    from config import Config
    from plugin import MSsqlClient
    client = MSsqlClient(**Config.module_config.huada.record_link)
    client.execute("""
    drop table access_records
    drop table area
    drop table auth
    drop table city
    drop table company
    drop table doors
    drop table o2
    drop table o3
    drop table o4
    drop table o5
    drop table o6
    drop table o7
    drop table person
    drop table usercard
    drop table virtualcard
    """)
    print('drop table success')
    



def list_index():
    a = [1, 2, 3, 4, 5]
    print(a.index(5))


def int2hex():
    a = '2777809901'
    print(str(hex(int(a)).upper()).removeprefix('0X'))

def hex2int():
    a = 'A59203ED'
    print(int(a, 16))


def 位移运算():
    a = 5
    b = 1
    print((a << 8) + b)


# 时间减法
def time_sub():
    from plugin import MyTime
    time1 = MyTime.timestr()
    timestamp1 = MyTime.timestampfrom(time1)
    print(timestamp1)

    time2 = MyTime.timestamp()
    print(time2)
    bool = MyTime.timestamp() - int(MyTime.timestampfrom(time1)) > 24 * 60 * 60
    print(bool)



# coding=utf-8
from requests import post

url = 'http://10.1.14.208:8090/developerCommonUserApi/queryOrgByUserAll/B10347DB8F7D08EC2FD5A55F235D0727'
data = 'MESSAGE={"requestParam": {"pageSize": "500","data": "","pageNo": "1"},"header":{"signature":"5eb7d4c6-f3f4-4f20-b187-9af0bc162799","token": "1649727535353"}}'
print(data)
headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
    }

resp = post(url, data=data, headers=headers)
print(resp.text)
print(resp.status_code)

if __name__ == '__main__':
    # executemany(1000000)
    # execute(10000)
    # executeevery(1000000)
    # insertmany(1000000)
    # hide_test()
    # extend_test()
    # copy_test1()
    # dict_copy_test()
    # test_dic_key()
    # do_init()
    # list_index()
    # int2hex()
    # hex2int()
    # 位移运算()
    # time_sub()
    posttest()
